package Java攻略._2_java_util_function包._3_Predicate接口;

import java.util.Arrays;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class _10_为常见情况添加常量 {

    public static final Predicate<String> LENGTH_FIVE = s -> s.length() == 5;
    public static final Predicate<String> STARTS_WITH_S = s -> s.startsWith("S");

    public static void main(String[] args) {

        _10_为常见情况添加常量 _10 = new _10_为常见情况添加常量();
        String s = _10.get(LENGTH_FIVE, "12345", "2345", "34567", "00000");
        System.out.println(s);
    }

    public String get(Predicate<String> predicate, String... names){

        return Arrays.stream(names)
                .filter(predicate)
                .collect(Collectors.joining(", "));
    }
}
